package com.itshare.video.mapper;

import com.itshare.video.pojo.po.Course;
import com.itshare.video.pojo.po.CourseExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface CourseMapper {
    long countByExample(CourseExample example);

    int deleteByExample(CourseExample example);

    @Delete({
        "delete from t_course",
        "where course_id = #{courseId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long courseId);

    @Insert({
        "insert into t_course (title, cover_image, ",
        "description, REVISION, ",
        "CREATED_BY, CREATED_TIME, ",
        "UPDATED_BY, UPDATED_TIME, ",
        "category_id, couse_detail, ",
        "teacher_id, price, ",
        "discount_price, is_hot, ",
        "attention, is_free, ",
        "delete_status)",
        "values (#{title,jdbcType=VARCHAR}, #{coverImage,jdbcType=VARCHAR}, ",
        "#{description,jdbcType=VARCHAR}, #{revision,jdbcType=INTEGER}, ",
        "#{createdBy,jdbcType=VARCHAR}, #{createdTime,jdbcType=TIMESTAMP}, ",
        "#{updatedBy,jdbcType=VARCHAR}, #{updatedTime,jdbcType=TIMESTAMP}, ",
        "#{categoryId,jdbcType=VARCHAR}, #{couseDetail,jdbcType=VARCHAR}, ",
        "#{teacherId,jdbcType=INTEGER}, #{price,jdbcType=DECIMAL}, ",
        "#{discountPrice,jdbcType=DECIMAL}, #{isHot,jdbcType=INTEGER}, ",
        "#{attention,jdbcType=INTEGER}, #{isFree,jdbcType=INTEGER}, ",
        "#{deleteStatus,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="courseId", before=false, resultType=Long.class)
    int insert(Course record);

    int insertSelective(Course record);

    List<Course> selectByExampleWithRowbounds(CourseExample example, RowBounds rowBounds);

    List<Course> selectByExample(CourseExample example);

    @Select({
        "select",
        "course_id, title, cover_image, description, REVISION, CREATED_BY, CREATED_TIME, ",
        "UPDATED_BY, UPDATED_TIME, category_id, couse_detail, teacher_id, price, discount_price, ",
        "is_hot, attention, is_free, delete_status",
        "from t_course",
        "where course_id = #{courseId,jdbcType=BIGINT}"
    })
    @ResultMap("com.itshare.video.mapper.CourseMapper.BaseResultMap")
    Course selectByPrimaryKey(Long courseId);

    int updateByExampleSelective(@Param("record") Course record, @Param("example") CourseExample example);

    int updateByExample(@Param("record") Course record, @Param("example") CourseExample example);

    int updateByPrimaryKeySelective(Course record);

    @Update({
        "update t_course",
        "set title = #{title,jdbcType=VARCHAR},",
          "cover_image = #{coverImage,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "REVISION = #{revision,jdbcType=INTEGER},",
          "CREATED_BY = #{createdBy,jdbcType=VARCHAR},",
          "CREATED_TIME = #{createdTime,jdbcType=TIMESTAMP},",
          "UPDATED_BY = #{updatedBy,jdbcType=VARCHAR},",
          "UPDATED_TIME = #{updatedTime,jdbcType=TIMESTAMP},",
          "category_id = #{categoryId,jdbcType=VARCHAR},",
          "couse_detail = #{couseDetail,jdbcType=VARCHAR},",
          "teacher_id = #{teacherId,jdbcType=INTEGER},",
          "price = #{price,jdbcType=DECIMAL},",
          "discount_price = #{discountPrice,jdbcType=DECIMAL},",
          "is_hot = #{isHot,jdbcType=INTEGER},",
          "attention = #{attention,jdbcType=INTEGER},",
          "is_free = #{isFree,jdbcType=INTEGER},",
          "delete_status = #{deleteStatus,jdbcType=INTEGER}",
        "where course_id = #{courseId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Course record);
}